package String;

import java.util.Arrays;

public class String1 {
    public static void main(String[] args) {
        char chs[]={'a','b','c'};
        String str1=new String(chs);
        System.out.println(str1);
        System.out.println(str1.charAt(1));
        String str2="def";
        System.out.println(str1.concat(str2));      //字符串拼接
        System.out.println(str1.equals(str2));
        String str3="ABC";
        System.out.println(str1.equalsIgnoreCase(str3));
        System.out.println("-----------------------");
        String str4="abcdef";
        System.out.println(str4.startsWith("abc")); //判断是否以指定字符串开头
        System.out.println(str4.startsWith("cde",2));   //判断在指定位置是否以指定字符串开头
        System.out.println("-----------------------");
        System.out.println(str4.endsWith("def"));   //判断是否以指定字符串结尾
        System.out.println("-----------------------");
        System.out.println(str4.isEmpty()); //判断是否为空串
        System.out.println("-----------------------");
        System.out.println(str4.contains("cde"));   //是否包含指定字符串
        System.out.println("-----------------------");
        System.out.println(str4.charAt(1));     //返回指定位置的字符
        System.out.println(str4.indexOf("c"));  //返回第一次出现该字符串的位置，从前往后找
        System.out.println(str4.lastIndexOf("c"));      //从后往前找
        System.out.println("-----------------------");
        System.out.println(str4.substring(6));      //字符串截取
        System.out.println(str4.substring(2,5));
        System.out.println("-----------------------");
        System.out.println(Arrays.toString(str4.toCharArray()));    //将字符串转换为char类型数组
        System.out.println(str4.toUpperCase()); //小写转大写
        System.out.println(str4.toUpperCase().toLowerCase());  //大写转小写
        System.out.println("-----------------------");
        System.out.println(str4.replace("ab","xx"));  //字符串替换
        String str5="   b   ";
        System.out.println(str5.trim());            //去空格

    }
}
/*
    String类型底层是char类型的数组,所有的字符串都可以看成是String类型的实例
 */
